package model.userModel;

import empty.users.Department;

import java.sql.SQLException;
import java.util.List;

public class DepartmentModel {

    public int insert(Department department) throws SQLException{
        String sql = "INSERT INTO departments (name, manager, number_of_people, company_id) VALUES (?, ?, ?, ?)";
        return Tool.DML(sql, department.getName(), department.getManager(), department.getNumber_of_people(), department.getCompany_id());
    }

    public int delete(Department department) throws SQLException{
        String sql = "DELETE FROM departments WHERE id = ?";
        return Tool.DML(sql, department.getId());
    }

    public int update(Department department) throws SQLException{
        String sql = "UPDATE departments SET name = ?, manager = ?, number_of_people = ?, company_id = ? WHERE id = ?";
        return Tool.DML(sql, department.getName(), department.getManager(), department.getNumber_of_people(), department.getCompany_id(), department.getId());
    }

    public List<Object []> findAll(Department department) throws SQLException{
        String sql = "SELECT * FROM departments";
        return Tool.DQL(sql);
    }

    public List<Object []> findByName(Department department) throws SQLException {
        String sql = "SELECT * FROM departments WHERE name = ?";
        return Tool.DQL(sql, department.getName());
    }

}
